package com.kalvan.core.db;

import com.alibaba.druid.pool.DruidDataSource;
import com.kalvan.core.security.DesUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DruidSecretBasicDataSource extends DruidDataSource {
    private static final long serialVersionUID = 1L;

    public static String decryptDB(String info) {
        try {
            return DesUtil.decryptExtraData(DesUtil.DEFAULT_KEY, info);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return info;
        }
    }

    public synchronized void setPassword(String password) {
        String newpassword = decryptDB(password);
        super.setPassword(newpassword);
    }

    public synchronized void setUrl(String url) {
        super.setUrl(url);
    }

    public synchronized void setUsername(String username) {
        String newusername = decryptDB(username);
        super.setUsername(newusername);
    }
}
